package scalaLearning.part2

object ConstructorDemo {
  def main(args: Array[String]): Unit = {
    val p1=new Person("jacky",20)
    println(p1)
  }
}

//构造器的快速入门
class Person(inName:String,inAge:Int){
  var name:String=inName
  var age:Int=inAge

  //重写了toString方法
  override def toString: String = {
    "name="+this.name+";age="+this.age
  }

  def this(name:String){
    //辅助构造器，必须在第一行显式调用主构造器
    this("jacky",20)
    this.name=name
  }
}